<script type="text/javascript">
	<?php if (count((array)$this->data) > 0): ?>
		<?php
		$inventory_arr = array();
		foreach ($this->data as $key => $inventory){
			$location_name = $inventory->m_Array['location_name'];
			$inventory = $inventory->toArray();
			$inventory['inventory_product_time'] = $this->partial('index/format/time.phtml', 'admin', array($inventory['inventory_product_time']));
			$inventory['inventory_expire_time'] = $this->partial('index/format/time.phtml', 'admin', array($inventory['inventory_expire_time']));
			$inventory['location_name'] = $location_name;
			
			$inventory_arr[$key] = $inventory;
		}
		?>
	<?php endif; ?>
	
	var inventory_arr = <?php echo Zend_Json::encode($inventory_arr) ?>;
	$(document).ready(function(){
		$("input[name^='inventory_id']").click(function(){
			var inventory_id = $(this).val();
			for (var key in inventory_arr){
				if (inventory_id == inventory_arr[key].inventory_id){
					var data = new Object;
					
					data.inbound_detail_product_code = inventory_arr[key].inventory_product_code ;
					data.inbound_detail_product_unit_code = inventory_arr[key].inventory_product_unit_code ;
					data.inbound_detail_product_quantity = inventory_arr[key].inventory_quantity ;
					data.inbound_detail_location_code = inventory_arr[key].inventory_location_code ;
					data.inbound_detail_product_time = inventory_arr[key].inventory_product_time ;
					data.inbound_detail_expire_time = inventory_arr[key].inventory_expire_time ;
					data.inbound_detail_lot_code = inventory_arr[key].inventory_lot_code ;
					data.location_name = inventory_arr[key].location_name ;
					
					if (parent.addProductToInboundDetail){
						parent.addProductToInboundDetail(data);
						$(this).removeAttr('checked');
						if (parent.closeDialog)
							parent.closeDialog();
					}else{
						for (var k in data){
							alert('k: ' + k + " : " + data[k]);
						}						
					}
					return false;
				}
			}
		});
	});
</script>

<form id='adminForm' name='adminForm' method='post' action=''>

	<!-- phần tìm kiếm -->
	<fieldset id="filter-bar" style="height: auto">
		<div class="filter-search fltlft">
			<label class="title">Tìm kiếm: </label>
			<label for="inventory_product_code">Mã hàng hóa</label>
			<?php echo $this->inventory_product_code_control->renderUiWidgetElement() ;?>
			<?php echo $this->inventory_product_code_control->getDescription() ;?>
			<label for="inventory_lot_code">Mã lot</label>
			<?php echo $this->inventory_lot_code_control->renderUiWidgetElement() ;?>
			<?php echo $this->inventory_lot_code_control->getDescription() ;?>			
			<?php echo $this->partial('index/search/submit.phtml', 'admin', array('onclick'=>"$('.filter-search input').val('');")) ?>
			<!-- <input type="submit" style="display:none"> -->			
		</div>		 
	</fieldset>
	<!-- / -->
	
	<!-- danh sách hiển thị -->
	<div class='clr'> </div>
	<table class='adminlist'>
		<thead>			
			<tr>
				<th width="1%">#</th>
				<th>
					<?php echo $this->partial('index/manage/header.phtml','admin',array('caption'=>$this->captions,'column'=>'inventory_product_code')); ?>
				</th>
				
				<th>
					<?php echo $this->partial('index/manage/header.phtml','admin',array('caption'=>$this->captions,'column'=>'inventory_product_unit_code')); ?>
				</th>
				
				<th>
					<?php echo $this->partial('index/manage/header.phtml','admin',array('caption'=>$this->captions,'column'=>'inventory_quantity')); ?>
				</th>
				
				<th>
					<?php echo $this->partial('index/manage/header.phtml','admin',array('caption'=>$this->captions,'column'=>'location_name')); ?>
				</th>			
				
				<th>
					<?php echo $this->partial('index/manage/header.phtml','admin',array('caption'=>$this->captions,'column'=>'inventory_product_time')); ?>
				</th>
				
				<th>
					<?php echo $this->partial('index/manage/header.phtml','admin',array('caption'=>$this->captions,'column'=>'inventory_expire_time')); ?>
				</th>
				
				<th>
					<?php echo $this->partial('index/manage/header.phtml','admin',array('caption'=>$this->captions,'column'=>'inventory_lot_code')); ?>
				</th>				
				
				<th width='5%'>Chọn</th>
			</tr>
		</thead>
		<tbody>
		<?php if (count($this->paginator) > 0): $no=0;?>
		<?php foreach ($this->paginator as $row): ?>
			<tr class='row<?php echo ($no++)%2 ?>'>
				<td>
					<?php echo $no;?>
				</td>
				<td class='left'>
					<?php echo $row->inventory_product_code; ?>
				</td>
				<td class='left'>
					<?php echo $row->inventory_product_unit_code; ?>
				</td>
				<td class='right'>
					<?php echo $this->partial('index/format/int.phtml','admin',array($row->inventory_quantity)); ?>
				</td>
				<td class='left'>
					<?php echo $row->m_Array['location_name']; ?>
				</td>
				<td class='center'>
					<?php echo $this->partial('index/format/time.phtml','admin',array($row->inventory_product_time)); ?>
				</td>
				<td class='center'>
					<?php echo $this->partial('index/format/time.phtml','admin',array($row->inventory_expire_time)); ?>
				</td>
				<td class='left'>
					<?php echo $row->inventory_lot_code; ?>
				</td>				
				<td class='center'><input type="radio" name="inventory_id[]" value="<?php echo $row->inventory_id ;?>" /></td>
			</tr>
		<?php endforeach; ?>
		<?php endif; ?>
		</tbody>
		<tfoot>
			<tr>
				<td colspan='12'>
					<div class='container'>
						<?php echo $this->paginationControl($this->paginator) ?>
					</div>
				</td>
			</tr>
		</tfoot>
	</table>
	<!-- / -->